import { getUser, hasUser } from "../models/user.ts";
import { Request, Response } from "express";
import { UserEntryIF } from "../types/entry.ts";

class userController {
  constructor() {}

  static async getUserById(req: Request, res: Response) {
    // const { id } = req.params
    const id = "1";
    await getUser([id], (user: UserEntryIF) => {
      if (!user) {
        return res.status(404).send("User not found");
      }
      res.send(user);
    });
  }

  static async login(req: Request, res: Response) {
    const { username, password } = req.body;

    if (!username || !password) {
      return res.status(400).json({ message: "请提供用户名和密码" });
    }

    await hasUser([username, password], (isUser: Boolean) => {
      if(isUser) {
        res.send(isUser);
      } else {
        res.status(500).json({data: '请提供正确的用户名和密码'})
      }
    });
  }
}

export default userController;
